The present invention relates to computer graphics, and more particularly to rasterization of 3D primitives within a graphics pipeline.
Traditional graphics rendering hardware clips geometric primitives (polygons, lines, points, etc.) to a view volume prior to rasterization based on the vertices that make up each primitive. Typically, the view volume is defined by six clipping planes (top, bottom, left, right, front, and back) and the clipping process uses homogeneous clip coordinates. After clipping and a perspective divide, vertex coordinates are referred to as xe2x80x9cnormalized device coordinatesxe2x80x9d. Further viewport and depth range transformations (i.e. a scale and bias) convert normalized device coordinates to window coordinates. Subsequent primitive assembly, rasterization, and interpolation steps use these window coordinates.
Clipping based on the left, right, top, and bottom clip planes guarantees that the rasterized pixels for a clipped primitive are within the rectangular screen region defined by the viewport. Additionally, clipping based on the near and far clip planes guarantees that the depth values for rasterized pixels are within the representable range of the depth buffer (i.e. 16-bit or 24-bit integers).
Use of near and far plane clipping is well established. The OpenGL(copyright) and Direct3D(copyright) programming interfaces both assume near and far plane clipping. Ignoring the near and far clip planes has been discussed in the literature and hardware implementations of such rasterizers are available. For more information such topic, reference may be made to: Olano, Marc and Trey Greer, xe2x80x9cTriangle Scan Conversion Using 2D Homogeneous Coordinatesxe2x80x9d, Proceedings of the 1997 SIGGRAPH/Eurographics Workshop on Graphics Hardware (Los Angeles, Calif., Aug. 2-4, 1997), ACM SIGGRAPH, New York, 1995; and James Blinn, Jim Blinn""s Corner: A Trip Down the Graphics Pipeline, Morgan Kaufmann, 1996; which are each incorporated herein by reference in their entirety.
Prior art FIG. 1 illustrates a clipping operation 10 involving a near plane 12 and a far plane 14. During such clipping operation 10, the rasterization of primitives 16 that extend beyond such near plane 12 and far plane 14 are truncated at the planes. A primitive 11 entirely behind the far clip plane 14 or a primitive 13 entirely in front of the near clip plane 16 is eliminated entirely. As shown in FIG. 1, the foregoing truncation may involve defining additional triangles 18 at the near plane 12 and far plane 14.
Mathematically, the primitives may, in fact, extend beyond the near and/or far clip planes (12 and 16), but truncation of the primitive occurs for the sake of rasterization hardware which traditionally uses fixed-point math for depth values for reasons of hardware efficiency and performance. Such operations are limited in their numeric range.
In several cases, near and far plane clipping is undesirable. Polygons such as an unbounded ground plane going off into the horizon are clipped to the far clip plane rather than extending to the horizon line. There is thus a need for a system and method capable of permitting such polygons to be rasterized correctly even if otherwise incorrect depth values result.
Another situation where near and far plane clipping is undesirable is stenciled shadow volumes for rendering shadowed scenes. Shadow volume algorithms rely on drawing closed polygonal boundaries to separate shadowed regions from lit regions. Unfortunately, when shadow volumes are clipped by the far and/or near clip planes, these polygonal boundaries are no longer closed due to clipping. This leads to incorrect shadow determination. There is thus a further need for a system and method capable of permitting shadow volumes to be rendered without shadow determination artifacts caused by far and/or near plane clipping.
A system, method and computer program product are provided for depth clamping in a hardware graphics pipeline. Initially, a depth value is identified. It is then determined as to whether a hardware graphics pipeline is operating in a depth clamping mode. If the hardware graphics pipeline is operating in the depth clamping mode, the depth value is clamped within a predetermined range utilizing the hardware graphics pipeline.
In one embodiment, the depth value may be associated with a primitive, a clipped portion of a primitive, a pixel, and/or a fragment. Further, the clamping may be carried out in a raster operation (ROP) module of the hardware graphics pipeline.
In another embodiment, the predetermined range may be defined by a near plane and a far plane. Further, the predetermined range may be programmable. As an option, the depth value may be clamped for shadow volume rendering.
In still another embodiment, it may be determined whether the hardware graphics pipeline is operating in the depth clamping mode utilizing a control bit. As an option, the control bit may indicate that the hardware graphics pipeline is not operating in the depth clamping mode by default. In such embodiment, a data structure for depth clamping may be stored in memory in a hardware graphics pipeline. Such data structure may include a control object for indicating whether a hardware graphics pipeline is operating in a depth clamping mode. In use, a depth value may be clamped within a predetermined range utilizing the hardware graphics pipeline, if the control object indicates that the hardware graphics pipeline is operating in the depth clamping mode.
As an option, a second clamping of the depth value may be performed within a second predetermined range utilizing the hardware graphics pipeline. Such second predetermined range may be defined between zero (0) and a maximum value associated with the hardware graphics pipeline.
In still yet another embodiment, the depth value may be converted from a first representation to a second representation. Optionally, the first representation may be a fixed-point representation and the second representation may be a floating-point representation. In the alternative, the first representation may be a floating-point representation and the second representation may be a fixed-point representation.
If the hardware graphics pipeline is not operating in the depth clamping mode, a clipping operation may be performed. Such clipping operation may be carried out in a raster operation (ROP) module of the hardware graphics pipeline.
Optionally, the depth clamping mode may be defined by a graphics application program interface. Moreover, the depth clamping mode may be defined by an extension to a graphics application program interface.
Another system, method and computer program product are provided for depth clamping involving a fragment in a hardware graphics pipeline. Initially, a depth value of a fragment is received. Subsequently, the depth value of the fragment is clamped within a predetermined range utilizing a hardware graphics pipeline.
Still another system, method and computer program product are provided for depth clamping in a hardware graphics pipeline. Initially, a primitive is received. Next, it is determined whether a hardware graphics pipeline is operating in a predetermined mode. If the hardware graphics pipeline is operating in the predetermined mode, a portion of the primitive is projected to at least one of a near plane and a far plane utilizing the hardware graphics pipeline.
Still yet another system, method and computer program product are provided for depth clamping in a hardware graphics pipeline. Initially, a depth value is identified for a graphics primitive. It is then determined as to whether a hardware graphics pipeline is operating in a depth clamping mode. If the hardware graphics pipeline is operating in the depth clamping mode, the graphics primitive is split into a plurality of portions. At least one of the portions has all depth values clamped to a predetermined value utilizing the hardware graphics pipeline.
The present technique thus provides a hardware mechanism, possibly controlled by a graphics application programming interface, where pixel coverage is determined either with consideration of near and far clip planes (i.e., conventional clipping operation) or without consideration of the near and far clip planes (i.e., a xe2x80x9cdepth clampingxe2x80x9d operation).
When rasterized fragments are generated with interpolated depth values beyond the range of a fixed-point depth buffer numeric range (due to the possible lack of near and far plane clipping), out-of-range interpolated depth values are clamped to the current depth range setting, guaranteeing that post-clamping depth values are within the depth buffer representable range prior to depth testing. This depth clamping operation is carried out when clipping ignores the near and far clip planes. To handle the potentially unbounded range for interpolated depth values without near and far plane clipping, depth value interpolation may be performed with floating-point math. Further, the depth clamping operation may be performed on a per-fragment basis.
Additionally, rasterized fragments with clip-space xe2x80x9cwxe2x80x9d values (usually understood to encode the eye-space distance from the viewer) that are less than or equal to zero may be discarded utilizing the aforementioned second clamping operation. This may avoid both rendering fragments that are logically xe2x80x9cbehindxe2x80x9d the viewer and numerically unstable operations (i.e., division by zero) during interpolation. Most rasterization standards (i.e., OpenGL(copyright)) do not require the generation of fragments with clip-space xe2x80x9cwxe2x80x9d values less than or equal to zero.
Thus, the present scheme performs depth testing with a xe2x80x9cwindow-space Zxe2x80x9d depth buffer which makes it compatible with existing programming interfaces such as OpenGL(copyright) and Direct3D(copyright) which assume a xe2x80x9cwindow-space Zxe2x80x9d depth buffer. Further, depth values are clamped to their minimum and maximum generatable values as determined by the current depth range state. It is this clamping that allows the present scheme of ignoring clipping to the near and far planes compatible with conventional xe2x80x9cwindow-space Zxe2x80x9d depth buffering.
These and other advantages of the present invention will become apparent upon reading the following detailed description and studying the various figures of the drawings.